﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Collections.Generic;
using System.Linq;
using System.Data.Linq;
using WX.WMS.DataModel;
using WX.WMS.Common;
using WX.WMS.BLL;

public partial class TransStockManager : PageBase
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            ViewState["SortOrder"] = "CREATE_TIME";
            ViewState["OrderDire"] = "Asc";
            
            init();
        }

    }

    protected void init()
    {
        object action = Request.QueryString["action"];

        DataBandStatusList();

        if (action == null)
        {
            searchBand();
        }
        else if (action.ToString().Equals("del"))
        {
            string ID = Request.QueryString["ID"].ToString();
            TransferBLL BllTransfer = new TransferBLL();
            if (BllTransfer.DeleteTransfer(ID)< 0)
            {
                ShowMessage("删除失败");
                
            }
            else {
              
                searchBand();
            }
        }

        this.CreateDateFrom.Attributes["readonly"] = "readonly";
        this.CreateDateTo.Attributes["readonly"] = "readonly";
    }

    protected void searchBand()
    {
        TransferBLL bll = new TransferBLL();

        if (this.CreateUser.Text.Trim() != "")
        {
            bll.AddLikeCondition("T_SYS_USER.NAME", this.CreateUser.Text.Trim());
        }
        if (this.CreateDateFrom.Text.Trim() != "" && this.CreateDateTo.Text.Trim() != "")
        {
            bll.AddBetweenCondition("CREATE_TIME", this.CreateDateFrom.Text.Trim(), this.CreateDateTo.Text.Trim(), true);
        }
        if (this.ddlStatus.SelectedValue != "-1")
        {
            bll.AddEqualCondition("STATE", this.ddlStatus.SelectedValue);
        }

        bll.AddOrderByCondition(ViewState["SortOrder"] + " " + ViewState["OrderDire"]);

        SearchResult.DataSource = bll.GetTransferList();
        SearchResult.DataBind();
    }
    protected void gvTransStockList_RowEditing(object sender, GridViewEditEventArgs e)
    {
        string ID = SearchResult.DataKeys[e.NewEditIndex]["TRANSFER_ID"].ToString();
        if (new TransferBLL().IsAudited(ID))
        {
            ShowMessage("审核通过的不能编辑");
        }
        else
        {
            Response.Redirect("TransStockDetail.aspx?Action=edit&ID=" + ID);
        }
    }
    protected void gvTransStockList_RowDeleting(object sender, GridViewDeleteEventArgs e)
    {
        string ID = SearchResult.DataKeys[e.RowIndex]["TRANSFER_ID"].ToString();
        if (new TransferBLL().IsAudited(ID))
        {
            ShowMessage("审核通过的不能删除");
        }
        else
        {
            Response.Redirect("TransStockManager.aspx?Action=del&ID=" + ID);
        }
    }
    protected void gvTransStockList_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        SearchResult.PageIndex = e.NewPageIndex;
        searchBand();
    }

    protected void DataBandStatusList()
    {
        CommomMethod.BindEnumForDropdwonList(this.ddlStatus, typeof(Enumerations.StockStatus));
        this.ddlStatus.Items.Insert(0, new ListItem("请选择", "-1"));
    }
    protected void searchButton_Click(object sender, ImageClickEventArgs e)
    {
        searchBand();
    }
}
